Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.get = get, exports.getSync = getSync, exports.set = set, exports.setSync = setSync, 
exports.isExpire = isExpire, exports.default = void 0;

var storage, KEY = "local_storage_record";

function get(t) {
    return (storage ? Promise.resolve(storage) : new Promise(function(t) {
        wx.getStorage({
            key: KEY,
            success: function(e) {
                return t(e.data);
            },
            fail: function() {
                return t({});
            }
        });
    })).then(function(e) {
        return storage = e, t ? e[t] : e;
    });
}

function getSync(e) {
    return storage || (storage = wx.getStorageSync(KEY) || {}), e ? storage[e] : storage;
}

function set(e, t) {
    return get().then(function() {
        return storage[e] = t;
    }).then(function() {
        return new Promise(function(e, t) {
            wx.setStorage({
                key: KEY,
                data: storage,
                success: e,
                fail: t
            });
        });
    });
}

function setSync(e, t) {
    getSync(), storage[e] = t, wx.setStorageSync(KEY, storage);
}

function isExpire(e, t) {
    getSync();
    var r = storage[e];
    return !r || Date.now() - r.time > t;
}

var _default = {
    get: get,
    set: set,
    getSync: getSync,
    setSync: setSync,
    isExpire: isExpire
};

exports.default = _default;